﻿@model MvcCmsOptIn.Models.OptInModel 
@{
    string botGuid = ViewBag.BotGuid.ToString();
}
<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <meta name="ROBOTS" content="NOINDEX,NOFOLLOW">
    <link href="@Url.Content("/RazorThemes/" + Model._Portal.SkinName + "/css/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("/RazorThemes/" + Model._Portal.SkinName + "/css/optin.css")" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="subscription_header">@ViewBag.Title <span>@ViewBag.Message</span></div>
    <div class="subscription_container">
        <div class="subscription_friend">Share this with a friend Email:<input type="text" id="friendEmail" class="subscription_friend_input" />
            Name:<input type="text" id="friendName" class="subscription_friend_input" /><a href="javascript:void(0);" onclick="AddFriend();">Add Friend</a><img src="/content/images/busy.gif" style="display:none;" id="saveFriend" />
        </div>
        <div class="subscription_main">
            <h1>
                Opt-In / Opt-Out Mail Manager</h1>
            <div class="">
                <form id="form1" action="" method="post">
                <table cellspacing="0" border="0" style="border-collapse: collapse;">
                    <tbody>
                        <tr>
                            <td>
                                <table width="600" cellspacing="0" cellpadding="5" border="0" class="frame">
                                    <tbody>
                                        <tr>
                                            <td class="toolbar">
                                                <a href="javascript:void(0);" onclick="SaveSubscriber();">
                                                    <img border="0" src="/areas/mvccmsoptin/content/buttons/save.gif" id="update" name="update">
                                                </a>
                                            </td>
                                            <td align="right">
                                                <span class="subscrption_donotcontact">
                                                    Do Not Contact @Html.CheckBox("DoNotContact", Model._Subscriber.DoNotContact)
                                                </span>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <table width="600" cellspacing="0" cellpadding="5" border="0" class="frame">
                                    <tr>
                                        <td colspan="2">
                                            <dl>
                                                <dt>Name </dt>
                                                <dd>
                                                    <input type="text" style="width: 90%;" class="required" id="Name" value="@Model._Subscriber.Name" name="Name">
                                                </dd>
                                            </dl>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td valign="top">
                                            <dl>
                                                <dt>EMail</dt>
                                                <dd>
                                                    @Html.TextBox("EMail", Model._Subscriber.EMail)
                                                </dd>
                                                <dt>Format</dt>
                                                <dd>
                                                    @Html.TextBox("Format", Model._Subscriber.Format)
                                                </dd>
                                            </dl>
                                        </td>
                                        <td align="right">
                                            <dl>
                                                <dt>Date Created </dt>
                                                <dd>
                                                    @Model._Subscriber.CreateDate
                                                </dd>
                                            </dl>
                                        </td>
                                    </tr>
                                </table>
                                <table width="600" cellspacing="0" cellpadding="5" border="0">
                                    <tr valign="top">
                                        <td class="formtitle">
                                            <span id="lblRecipients">Lists</span>
                                        </td>
                                        <td class="formdata">
                                            <table style="width: 400px; font-size: 9px;">
                                                <tbody>
                                                    <tr>
                                                        <td style="text-align: left; padding-left: 20px; width: 50%;">
                                                            &nbsp;
                                                        </td>
                                                        <td style="text-align: left; padding-left: 40px; width: 50%; font-weight: bold;">
                                                            Subscribed to
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <span style="display: inline-block; width: 400px;" id="lstRecipients">
                                                <table border="0" style="vertical-align: middle;">
                                                    <tbody>
                                                        <tr>
                                                            <td valign="top">
                                                            </td>
                                                            <td align="center" rowspan="2">
                                                                <select class="recipients_select" id="availableLists" multiple="multiple" name="availableLists"
                                                                    size="4">
                                                                    @if (Model._Lists != null)
                                                                    {
                                                                        foreach (var list in Model._Lists)
                                                                        {                                                        
                                                                        <option value="@list.ListID">@list.ListName</option>
                                                                        }
                                                                    }
                                                                </select>
                                                            </td>
                                                            <td width="100px" align="center" rowspan="2">
                                                                <input type="button" id="toRight" value="&gt;&gt;"><br>
                                                                <input type="button" id="toLeft" value="&lt;&lt;">
                                                            </td>
                                                            <td align="center" rowspan="2">
                                                                <select class="recipients_select" multiple="multiple" id="currentLists" name="currentLists"
                                                                    size="4">
                                                                    @if (Model._AssignedLists != null)
                                                                    {
                                                                        foreach (var list in Model._AssignedLists)
                                                                        {
                                                                        <option value="@list.ListID">@list.ListName</option>
                                                                        }
                                                                    }
                                                                </select>
                                                            </td>
                                                            <td valign="top">
                                                                <img src="/content/images/busy.gif" style="display: none;" id="savingList" />
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="bottom">
                                                            </td>
                                                            <td valign="bottom">
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </span>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </table>
                @Html.Hidden("SubscriberID", Model._Subscriber.SubscriberID)
                @Html.Hidden("BotGuid", botGuid)
                </form>
            </div>
        </div>
    </div>
    <script src="@Url.Content("/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("/areas/mvccmsoptin/Scripts/jquery.validate.js")" type="text/javascript"></script>
    <script id="General" type="text/javascript">
        function SaveSubscriber() {
            $("#form1").submit();
        }
        $(document).ready(function () {
            $("#form1").validate();
        });        
    </script>
    <script id="Add/RemoveList" type="text/javascript">
        function AddFriend(listId) {
            $("#saveFriend").show();
            $.post("/optinajax/addfriend/",
		    { Email: $('#friendEmail').val(), Name: $('#friendName').val() },
            function (data) {
                if (data.error) {
                    alert(data.error);
                }
                $("#saveFriend").attr("src", "/content/images/greencheck.gif");
            }, "json");
        }  
    </script>
    <script id="Add/Remove List(s)" type="text/javascript">
        $(document).ready(function () {
            var suppliedSelect = jQuery('#availableLists');
            jQuery('#toRight').click(function () {
                suppliedSelect.find(':selected').each(function (index, elem) {
                    var selectElem = $(elem);
                    if (selectElem.val()) {
                        AddList(selectElem.val());
                        selectElem.appendTo('#currentLists');
                    }
                });
            });
        });
        $(document).ready(function () {
            var suppliedSelect = jQuery('#currentLists');
            jQuery('#toLeft').click(function () {
                suppliedSelect.find(':selected').each(function (index, elem) {
                    var selectElem = $(elem);
                    if (selectElem.val()) {
                        RemoveList(selectElem.val());
                        selectElem.appendTo('#availableLists');
                    }
                });
            });
        });
    </script>
    <script id="Add/RemoveList" type="text/javascript">
        function RemoveList(listId) {
            $("#savingList").show();
            $.post("/optinajax/removelistfromsubscriber/",
		    { SubscriberID: $('#SubscriberID').val(), ListID: listId },
            function (data) {
                if (data.error) {
                    alert(data.error);
                }
                $("#savingList").hide();
            }, "json");
        }
        function AddList(listId) {
            $("#savingList").show();
            $.post("/optinajax/addlisttosubscriber/",
		    { SubscriberID: $('#SubscriberID').val(), ListID: listId, Confirmed: true, useHTML: true },
            function (data) {
                if (data.error) {
                    alert(data.error);
                }
                $("#savingList").hide();
            }, "json");
        }    
    </script>
</body>
</html>
